package com.ruoyi.web.controller.system;

import java.io.IOException;
import java.util.List;
import java.util.Arrays;
import java.util.Map;

import lombok.RequiredArgsConstructor;

import javax.servlet.ServletException;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyChannelInfoVo;
import com.ruoyi.system.bo.ZsyyChannelInfoQueryBo;
import com.ruoyi.system.bo.ZsyyChannelInfoAddBo;
import com.ruoyi.system.bo.ZsyyChannelInfoEditBo;
import com.ruoyi.system.service.IZsyyChannelInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 通道管理Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "通道管理控制器", tags = {"通道管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/channelInfo")
public class ZsyyChannelInfoController extends BaseController {

    private final IZsyyChannelInfoService iZsyyChannelInfoService;

    /**
     * 查询通道管理列表
     */
    @ApiOperation("查询通道管理列表")
    @PreAuthorize("@ss.hasPermi('system:channelInfo:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyChannelInfoVo> list(@Validated ZsyyChannelInfoQueryBo bo) {
        return iZsyyChannelInfoService.queryPageList(bo);
    }
    /**
     * 查询通道管理列表
     */
    @ApiOperation("通道下拉列表")
    @GetMapping("/channelList")
    public AjaxResult channelList(@Validated ZsyyChannelInfoQueryBo bo) {
        return AjaxResult.success(iZsyyChannelInfoService.channelList(bo)) ;
    }

    /**
     * 导出通道管理列表
     */
    @ApiOperation("导出通道管理列表")
    @PreAuthorize("@ss.hasPermi('system:channelInfo:export')")
    @Log(title = "通道管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyChannelInfoVo> export(@Validated ZsyyChannelInfoQueryBo bo) {
        List<ZsyyChannelInfoVo> list = iZsyyChannelInfoService.queryList(bo);
        ExcelUtil<ZsyyChannelInfoVo> util = new ExcelUtil<ZsyyChannelInfoVo>(ZsyyChannelInfoVo.class);
        return util.exportExcel(list, "通道管理");
    }

    /**
     * 获取通道管理详细信息
     */
    @ApiOperation("获取通道管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:channelInfo:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyChannelInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyChannelInfoService.queryById(id));
    }

    /**
     * 新增通道管理
     */
    @ApiOperation("新增通道管理")
    @PreAuthorize("@ss.hasPermi('system:channelInfo:add')")
    @Log(title = "通道管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyChannelInfoAddBo bo) {
        return toAjax(iZsyyChannelInfoService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改通道管理
     */
    @ApiOperation("修改通道管理")
    @PreAuthorize("@ss.hasPermi('system:channelInfo:edit')")
    @Log(title = "通道管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyChannelInfoEditBo bo) {
        return toAjax(iZsyyChannelInfoService.updateByEditBo(bo) ? 1 : 0);
    }
    /**
     * 修改通道管理
     */
    @ApiOperation("生成二维码")
    @Log(title = "通道管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping("/getQRcode")
    public AjaxResult getQRcode(@Validated @RequestBody Map<String, String> map) throws ServletException, IOException {
        return AjaxResult.success(iZsyyChannelInfoService.getQRcode(map));
    }
    /**
     * 开关闸控制
     */
    @ApiOperation("开关闸控制")
    @RepeatSubmit
    @PutMapping("/controlCha")
    public AjaxResult controlCha(@Validated @RequestBody Map<String, String> map) {
        return AjaxResult.success(iZsyyChannelInfoService.controlCha(map));
    }

    /**
     * 删除通道管理
     */
    @ApiOperation("删除通道管理")
    @PreAuthorize("@ss.hasPermi('system:channelInfo:remove')")
    @Log(title = "通道管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyChannelInfoService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
